package mock

import "github.com/boltdb/bolt"

var bucketName = []byte("data")

type Store struct {
	db *bolt.DB
}

func NewStore(path string) (*Store, error) {
	bopts := &bolt.Options{}
	db, err := bolt.Open(path, 0600, bopts)
	if err != nil {
		return nil, err
	}

	tx, err := db.Begin(true)
	if err != nil {
		return nil, err
	}

	_, err = tx.CreateBucketIfNotExists(bucketName)
	if err != nil {
		return nil, err
	}

	s := &Store{
		db: db,
	}

	return s, nil
}


func (s *Store) Close() error {
	return s.db.Close()
}


func (s *Store) BatchTx() (*bolt.Tx, error) {
	tx, err := s.db.Begin(true)
	if err != nil {
		return nil, err
	}

	return tx, nil
}